using System;
using System.Configuration;
using System.Collections;


namespace Ddb_Demo.Config
{

    // Define the ServerElement.
    public class ServerElement :
        ConfigurationElement
    {

        // Test flag.
        private static bool _displayIt = false;

        public ServerElement(String newName,
            String ip, int newPort)
        {
            Name = newName;
            IP = ip;
            Port = newPort;

        }

        public ServerElement()
        {

        }

        public ServerElement(string elementName)
        {
            Name = elementName;
        }

        [ConfigurationProperty("name",
            DefaultValue = "DDBServer",
            IsRequired = true,
            IsKey = true)]
        public string Name
        {
            get
            {
                return (string)this["name"];
            }
            set
            {
                this["name"] = value;
            }
        }

        [ConfigurationProperty("ip",
            DefaultValue = "127.0.0.1",
            IsRequired = true)]
        public string IP
        {
            get
            {
                return (string)this["ip"];
            }
            set
            {
                this["ip"] = value;
            }
        }

        [ConfigurationProperty("port",
            DefaultValue = (int)0,
            IsRequired = false)]
        [IntegerValidator(MinValue = 0,
            MaxValue = 8080, ExcludeRange = false)]
        public int Port
        {
            get
            {
                return (int)this["port"];
            }
            set
            {
                this["port"] = value;
            }
        }

        protected override void DeserializeElement(
           System.Xml.XmlReader reader,
            bool serializeCollectionKey)
        {
            base.DeserializeElement(reader,
                serializeCollectionKey);

            // Enter your custom processing code here.
            
        }


        protected override bool SerializeElement(
            System.Xml.XmlWriter writer,
            bool serializeCollectionKey)
        {
            bool ret = base.SerializeElement(writer,
                serializeCollectionKey);

            // Enter your custom processing code here.

           
            return ret;

        }


        protected override bool IsModified()
        {
            bool ret = base.IsModified();

            // Enter your custom processing code here.

            Console.WriteLine("ServerElement.IsModified() called.");

            return ret;
        }


    }
}

